在本教程的这一步骤中,您将实现在应用程序描述面板中处理交互的功能:
为小组件描述面板创建交互:
onProjectLoaded()
函数中为 Back button 添加事件处理程序。virtual void onProjectLoaded() KZ_OVERRIDE
{
...
//为 Back button 添加处理程序。
m_backButton->addMessageHandler(Button3D::PressedMessage, bind(&ProgrammerTutorialApplication::onBackButtonClicked, this, placeholders::_1));
}
ProgrammerTutorialApplication
类中的 onListBoxItemSelected()
函数后实现Back button 点击消息的事件处理程序。false
。接下来,将节点不透明度设置为 0.0f
,使其透明。Widget Description Layer 节点隐藏,但其余可见,以阻止动画完成前的用户输入。class ProgrammerTutorialApplication : public ExampleApplication { ... //来自 Back button 的 Button.Pressed 消息处理程序。 //将选定列表框项移回其原来的位置。 void onBackButtonClicked(ButtonConcept::PressedMessageArguments& /*messageArguments*/) { //取消选择之前选择的列表框项。 m_widgetList->selectItem(nullopt); //移除旧回放,以重置值。 removePlaybacks(); //按相反方向开始摄像机的动画。 PropertyAnimationTimelineSharedPtr cameraTimeline = PropertyAnimationTimeline::create(getDomain(), ".", Node3D::RenderTransformationProperty, m_cameraAnimation); cameraTimeline->setDirectionBehavior(Timeline::DirectionBehaviorReverse); SceneGraphTimelinePlaybackContext cameraContext(*m_camera); m_cameraPlayback = cameraTimeline->createPlayback(cameraContext); getDomain()->getRootTimelineClock()->addTimelinePlayback(m_cameraPlayback); //按相反方向开始选定项的动画化。 PropertyAnimationTimelineSharedPtr selectedItemTimeline = PropertyAnimationTimeline::create(getDomain(), ".", Node3D::LayoutTransformationProperty, m_selectedItemAnimation); selectedItemTimeline->setDirectionBehavior(Timeline::DirectionBehaviorReverse); SceneGraphTimelinePlaybackContext selectedItemContext(*m_selectedItem); m_widgetHighlightPlayback = selectedItemTimeline->createPlayback(selectedItemContext); getDomain()->getRootTimelineClock()->addTimelinePlayback(m_widgetHighlightPlayback); //开始动画以隐藏 Widget Description Layer。 PropertyAnimationTimelineSharedPtr widgetDescriptionVisibilityTimeline = PropertyAnimationTimeline::create(getDomain(), ".", Node::VisibleProperty, m_widgetDescriptionVisibilityAnimation); SceneGraphTimelinePlaybackContext listBoxContext(*m_widgetDescriptionNode); m_widgetDescriptionVisibilityPlayback = widgetDescriptionVisibilityTimeline->createPlayback(listBoxContext); getDomain()->getRootTimelineClock()->addTimelinePlayback(m_widgetDescriptionVisibilityPlayback); //使 Widget Description Layer 透明。 m_widgetDescriptionNode->setProperty(Node::OpacityProperty, 0.0f); } };
void onListBoxItemSelected(ListBoxConcept::itemSelectedMessageArguments& messageArguments) { ... if (selectedItemIndex) { ... //通过将Widget Description Layer 设置为可见,显示小组件描述。 if (m_widgetDescriptionVisibilityPlayback) { ... } ... //使Widget Description Layer 不透明。 m_widgetDescriptionNode->setProperty(Node::OpacityProperty, 1.0f); } }
onBackButtonClicked()
函数后,添加从时间线时钟移除旧回放以重置摄像机值的函数://从时间线时钟移除旧回放。 void removePlaybacks() { TimelineClockSharedPtr timelineClock = getDomain()->getRootTimelineClock(); if (m_cameraPlayback) { timelineClock->removeTimelinePlayback(*m_cameraPlayback); m_cameraPlayback.reset(); } if (m_widgetHighlightPlayback) { timelineClock->removeTimelinePlayback(*m_widgetHighlightPlayback); m_widgetHighlightPlayback.reset(); } if (m_backButtonEnablePlayback) { timelineClock->removeTimelinePlayback(*m_backButtonEnablePlayback); m_backButtonEnablePlayback.reset(); } if (m_widgetDescriptionVisibilityPlayback) { timelineClock->removeTimelinePlayback(*m_widgetDescriptionVisibilityPlayback); m_widgetDescriptionVisibilityPlayback.reset(); } }